#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import json

# API接口的URL
# url = 'http://localhost:5000/predict'
url = 'http://172.20.9.82:5001/predict'

# 请求的数据
data = {
    "features": [5.1, 3.5, 1.4, 1.2]
}

# 设置请求头
headers = {
    "Content-Type": "application/json"
}

# 发送POST请求
response = requests.post(url, headers=headers, data=json.dumps(data))

# 检查响应状态码
if response.status_code == 200:
    # 解析响应数据
    result = response.json()
    prediction = result['prediction']

    # 类别标签映射
    class_names = {
        0: "Iris Setosa",
        1: "Iris Versicolor",
        2: "Iris Virginica"
    }

    # 打印预测结果
    print("Prediction:", class_names[prediction])
else:
    print("Error:", response.status_code, response.text)